# config ssh
set -eux

# close mem swap
# swapoff -a

mkdir -p /zion0/git_proj/${HOSTNAME}
mkdir -p /zion0/${HOSTNAME}/var/log/ccache
mkdir -p /zion0/${HOSTNAME}/var/log/distccd
mkdir -p /zion0/ccache_dir

# run distccd
cat > /zion0/git_proj/${HOSTNAME}/run_distccd.sh <<"EOF"
set -eux

echo '' > /zion0/${HOSTNAME}/var/log/distccd/distccd.log  
chmod 777 -R /zion0/${HOSTNAME}/var/log/distccd/
chown distcc:root -R  /zion0/${HOSTNAME}/var/log/ccache/
chown distcc:root -R  /zion0/${HOSTNAME}/var/log/distccd/

# for debug
#    --verbose --log-level=debug \
/usr/local/bin/distccd  --daemon --user distcc \
    --allow 172.16.2.0/24  --allow 192.168.1.0/24 --listen 0.0.0.0 \
    --nice 20 --jobs $(nproc) \
    --log-file=/zion0/${HOSTNAME}/var/log/distccd/distccd.log  

tail -f /dev/null
EOF

# distccd 上 需要包含 源代码
docker rm -f distccd || echo 0
docker run -d  \
    --name distccd \
    --restart always \
    --privileged=true \
    --network host \
    -v /zion0/etc/ssh/ssh_config:/etc/ssh/ssh_config:ro \
    -v /root/.ssh:/root/.ssh \
    -v /root/.config:/root/.config \
    -v /zion0/git_proj:/zion0/git_proj \
    -v /zion0/${HOSTNAME}/var/log/ccache:/zion0/${HOSTNAME}/var/log/ccache \
    -v /zion0/${HOSTNAME}/var/log/distccd:/zion0/${HOSTNAME}/var/log/distccd \
    -v /zion0/ccache_dir:/zion0/ccache_dir \
    openeuler/openeuler:22.03-lts-sp2-llvm-ccache-distcc \
    bash /zion0/git_proj/${HOSTNAME}/run_distccd.sh


# tail -f /zion0/${HOSTNAME}/var/log/distccd/distccd.log
